import tkinter
import ctypes
import win32process
import winreg
from sys import executable, exit
from subprocess import Popen
from threading import Thread
from keyboard import wait
from os import _exit
def is_admin():
    try:
        return ctypes.windll.shell32.IsUserAnAdmin()
    except:
        return False
if not is_admin():
    ctypes.windll.shell32.ShellExecuteW(None, "runas", executable, __file__, None, 1)
    exit()
def kill():
    button1["text"] = "执行中..."
    root.update()
    Popen(("taskkill", "/f", "/im", "Smonitor.exe")).wait()
    Popen(("taskkill", "/f", "/im", "Student.exe")).wait()
    button1["text"] = "关闭(Alt+k)"
def fix_desktop():
    button2["text"] = "执行中..."
    root.update()
    Popen(("taskkill", "/f", "/im", "explorer.exe")).wait()
    win32process.CreateProcess("C:/Windows/explorer.exe", "", None, None, 0, win32process.CREATE_NO_WINDOW, None, None, win32process.STARTUPINFO())
    button2["text"] = "恢复桌面(Alt+f)"
def enable_taskmgr():
    button3["text"] = "执行中..."
    root.update()
    winreg.SetValueEx(winreg.OpenKey(winreg.HKEY_CURRENT_USER, r"Software\Microsoft\Windows\CurrentVersion\Policies\System", 0, winreg.KEY_WRITE), "DisableTaskMgr", 0, winreg.REG_DWORD, 0)
    button3["text"] = "恢复任务管理器(Alt+e)"
def disable_taskmgr():
    button4["text"] = "执行中..."
    root.update()
    winreg.SetValueEx(winreg.OpenKey(winreg.HKEY_CURRENT_USER, r"Software\Microsoft\Windows\CurrentVersion\Policies\System", 0, winreg.KEY_WRITE), "DisableTaskMgr", 0, winreg.REG_DWORD, 1)
    button4["text"] = "禁用任务管理器(Alt+d)"
def k():
    while True:
        wait("Alt+k")
        kill()
def f():
    while True:
        wait("Alt+f")
        fix_desktop()
def e():
    while True:
        wait("Alt+e")
        enable_taskmgr()
def d():
    while True:
        wait("Alt+d")
        disable_taskmgr()
root = tkinter.Tk()
root.title("关闭伽卡他卡电子教室学生端")
root.iconbitmap("./icon.ico")
root.protocol("WM_DELETE_WINDOW", lambda : _exit(0))
lable1 = tkinter.Label(root, text = "欢迎使用关闭伽卡他卡电子教室学生端\n")
lable1.pack()
button1 = tkinter.Button(root, text = "关闭(Alt+k)", command = kill)
button1.pack()
tkinter.Label(root).pack()
button2 = tkinter.Button(root, text = "恢复桌面(Alt+f)", command = fix_desktop)
button2.pack()
tkinter.Label(root).pack()
button3 = tkinter.Button(root, text = "恢复任务管理器(Alt+e)", command = enable_taskmgr)
button3.pack()
tkinter.Label(root).pack()
button4 = tkinter.Button(root, text = "禁用任务管理器(Alt+d)", command = disable_taskmgr)
button4.pack()
tkinter.Label(root).pack()
Thread(target = k).start()
Thread(target = f).start()
Thread(target = e).start()
Thread(target = d).start()
root.mainloop()